import Vue from 'vue'
import Vuex from '@lib/x_.js'
import device from '../utils/device.js'
Vue.use(Vuex)
import { dicGetItemByCode } from '@api/dic.js'
import { tagPageQueryList } from '@api/tag.js'
import { userPageQueryList } from '@api/user.js' 
import { testGetSugarDic } from '@api/test.js'

import { templateFollowPageQueryList } from '@api/followTemplate.js'
import { typeFollowQueryList } from '@api/typeFollow.js'
import { typeInterventionQueryList } from '@api/typeIntervention.js'
import { templateInterventionPageQueryList } from '@api/interventionTemplate.js'
import { organPageQueryList } from '@api/organ.js'
import { employeePageQueryList } from '@api/employee.js'
export default new Vuex.Store({
	modules: {},
	state: {
        hidemenu: false,
        store: 'store...',
        menus: [],
        device: device(),
        user: {username:''},
        familyList: [],
        diseaseTypeList: [],
        diseaseHistoryList: [],
        familyHistoryList: [],
        nowTreatmentList: [],
        tagList: [],
        userList: [],
        sugarTime: [],
        marryTypeList: [],
        allergicList: [],
        typeFollowList: [], //随访类型
        typeInterventionList: [],
        templateFollowList: [], //随访模板
        templateInterventionList: [],
        organList: [],
        employeeList: [],
	},
	getters: {
        
    },
	mutations: {
		resetMobile(state) {state.device = device();},
        toggleMenu(state){state.hidemenu = !state.hidemenu;},
        setMenus(state,menus){
            if (menus && menus.length) {
                state.menus = menus;
            }
        },
        setUser(state,user){
            state.user = user;
        },
        setFamilyList(state,res){
            state.familyList = res;
        },
        setDiseaseTypeList(state,res){
            state.diseaseTypeList = res;
        },
        setDiseaseHistoryList(state,res){
            state.diseaseHistoryList = res;
        },
        setFamilyHistoryList(state,res){
            state.familyHistoryList = res;
        },
        setNowTreatmentList(state,res){
            state.nowTreatmentList = res;
        },
        setTagList(state,res){
            state.tagList = res;
        },
        setUserList(state,res){
            state.userList = res;
        },
        setSugarTime(state,time){
            state.sugarTime = time;
        },
        setMarryTypeList(state,list){
            state.marryTypeList = list;
        },
        setAllergicList(state,list) {
            state.allergicList = list;
        },
        setTypeFollowList(state,list) {
            state.typeFollowList = list
        },
        setTypeInterventionList(state,list) {
            state.typeInterventionList = list
        },
        // setTypeInterventionList
        setTemplateFollowPageQueryList(state,list){
            state.templateFollowList = list
        },
        setTemplateInterventionPageQueryList(state,list){
            state.templateInterventionList = list
        },
        setOrganList(state,list){
            state.organList = list;
        },
        setEmployeeList(state,list){
            state.employeeList = list;
        },
        
	},
	actions: {
        testGetSugarDic() {
            testGetSugarDic().then(res => res.code==='0'&&this.commit('setSugarTime',res.data))
        },
        getFamilyList(){
            dicGetItemByCode({typeCode:'family_relationship'}).then(res => this.commit('setFamilyList',res.data))
            dicGetItemByCode({typeCode:'family_relationship'}).then(res => {
                console.log('res-->', res)
            })
        },

        // marry_flag
        getMarryTypeList() {
            dicGetItemByCode({typeCode:'marry_flag'}).then(res => res.code==='0'&&this.commit('setMarryTypeList',res.data))
        },
        getDiseaseTypeList(){
            dicGetItemByCode({typeCode:'disease_type'}).then(res => res.code==='0'&&this.commit('setDiseaseTypeList',res.data))
        },
        getDiseaseHistoryList(){
            dicGetItemByCode({typeCode:'medical_history'}).then(res => res.code==='0'&&this.commit('setDiseaseHistoryList',res.data))
        },
        // allergic_history
        getAllergicList() {
            dicGetItemByCode({typeCode:'allergic_history'}).then(res => res.code==='0'&&this.commit('setAllergicList',res.data))
        },
        getFamilyHistoryList(){
            dicGetItemByCode({typeCode:'family_history'}).then(res => res.code==='0'&&this.commit('setFamilyHistoryList',res.data))
        },
        getNowTreatmentList(){
            dicGetItemByCode({typeCode:'treatment'}).then(res => res.code==='0'&&this.commit('setNowTreatmentList',res.data))
        },
        getTagList() {
            tagPageQueryList({page:1,pageSize:1000}).then(res => res.code==='0'&&this.commit('setTagList',res.data.items))
        },
        getUserList() {
            userPageQueryList({page: 1,pageSize: 1000}).then(res => res.code==='0'&&this.commit('setUserList',res.data.items))
        },
        typeFollowQueryList() {
            console.log('store typeFollowQueryList...')
			typeFollowQueryList().then(res => {
				if (res.code === '0') {
                    this.commit('setTypeFollowList',res.data)
				}
			})
        },
        typeInterventionQueryList() {
            typeInterventionQueryList({page:1,pageSize:500}).then(res => {
                if (res.code === "0") {
                    // this.typeInterventionList = res.data;
                    this.commit('setTypeInterventionList',res.data)
                }
            })
        },
        templateFollowPageQueryList() {
			templateFollowPageQueryList({ page: 1, pageSize: 1000 }).then(res => {
				if (res.code === '0') {
                    this.commit('setTemplateFollowPageQueryList',res.data.items)
				}
			})
        },
        templateInterventionPageQueryList(){
            templateInterventionPageQueryList({ page: 1, pageSize: 1000 }).then(res => {
                if (res.code === '0') {
                    this.commit('setTemplateInterventionPageQueryList',res.data.items)
				}
            })
        },
        organPageQueryList(){
            organPageQueryList({ page: 1, pageSize: 1000 }).then(res => {
                if (res.code === '0') {
                    this.commit('setOrganList',res.data.items)
				}
            })
        },
        employeePageQueryList(){
            employeePageQueryList({ page: 1, pageSize: 1000 }).then(res => {
                if (res.code === '0') {
                    this.commit('setEmployeeList',res.data.items)
				}
            })
        },
        
        
    }
})




